#include<bits/stdc++.h>
#define il inline
#define ct const
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
#define dl double
#define N 800010
#define ri register
using namespace std;
//bool ppp;
il int read(){
	ri int x=0;ri char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x;
}
il void write(ri int x){
	ri int cnt=0;ri char f[20];
	if(!x) putchar('0');
	while(x){
		f[cnt++]=x%10+'0';
		x/=10;
	}
	while(cnt) putchar(f[--cnt]);
	putchar('\n');
}
int head[N],nxt[N<<1],to[N<<1],w[N<<1],t=1;
il void add(ri int c,ri int b,ri int a){
	nxt[++t]=head[a];head[a]=t;to[t]=b;w[t]=c;
	nxt[++t]=head[b];head[b]=t;to[t]=a;w[t]=c;
}
int n,sum,mx[N],rt,sz[N];
ll ans[N<<1],f[N][22],Ans;
bool vis[N];
il void getrt(ri int x,ri int fa){
	sz[x]=1;mx[x]=0;
	for(ri int i=head[x];i;i=nxt[i])
		if(to[i]!=fa&&!vis[to[i]]){
			getrt(to[i],x);
			sz[x]+=sz[to[i]];
			mx[x]=max(mx[x],sz[to[i]]); 
		}
	mx[x]=max(mx[x],sum-sz[x]);
	if(mx[x]<mx[rt]) rt=x;
}
il void insert(ri int x,ri int i,ri bool k){
	if(k){
		for(ri int j=w[i];j<=20;++j) f[x][w[i]]+=f[to[i]][j];
		for(ri int j=1;j<w[i];++j) f[x][j]+=f[to[i]][j];
	}
	else{
		for(ri int j=w[i];j<=20;++j) f[x][w[i]]-=f[to[i]][j];
		for(ri int j=1;j<w[i];++j) f[x][j]-=f[to[i]][j];
	}
}
il void dfs1(ri int x,ri int fa){
	memset(f[x],0,sizeof(f[x]));f[x][20]=1;
	for(ri int i=head[x];i;i=nxt[i])
		if(to[i]!=fa&&!vis[to[i]]){
			dfs1(to[i],x);
			insert(x,i,1);
		}
}
il ll erase(ri int x,ri int mn){
	ri ll a[22],b[22];
	memcpy(a,f[x],sizeof a);
	memcpy(b,f[rt],sizeof b);
	for(ri int i=mn+1;i<=20;++i){
		a[mn]+=a[i];b[mn]+=b[i];
	}
	a[mn+1]=0;
	ri ll res=0,tmp1=0,tmp2=0;
	for(ri int i=mn;i;--i){
		tmp1+=b[i];tmp2+=a[i+1];
		res+=(a[i]*tmp1+b[i]*tmp2)*i;
	}
	return res;
}
il void dfs2(ri int x,ri int fa,ri int mn){
	ans[fa]+=erase(x,mn);
	for(ri int i=head[x];i;i=nxt[i])
		if(i!=(fa^1)&&!vis[to[i]])
			dfs2(to[i],i,min(mn,w[i]));
}
il void calc(ri int x){
	dfs1(x,0);
	for(ri int i=head[x];i;i=nxt[i])
		if(!vis[to[i]]){
			insert(x,i,0);
			dfs2(to[i],i,w[i]);
			insert(x,i,1);
		}
	for(ri int i=head[x];i;i=nxt[i])
		if(!vis[to[i]]){
			insert(x,i,0);
			Ans+=erase(to[i],w[i]);
		}
}
il void solve(ri int x){
	vis[x]=1;calc(x);getrt(x,0);
	for(ri int i=head[x];i;i=nxt[i])
		if(!vis[to[i]]){
			sum=sz[to[i]];
			getrt(to[i],rt=0);
			solve(rt);
		}
}
//bool pppp;
signed main(){
//	cerr<<(&ppp-&pppp)/1024.0/1024.0<<"\n";
	freopen("tatooine.in","r",stdin);
	freopen("tatooine.out","w",stdout);
	sum=n=read();mx[0]=1e9;
	for(ri int i=1;i<n;++i) add(read(),read(),read());
	getrt(1,0);solve(rt);
	for(ri int i=1;i<n;++i) write(Ans-ans[i<<1]-ans[i<<1|1]);
	return 0;
}

